﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using System.Runtime.Serialization;

namespace Dark_Dungeon
{
    [Serializable()]
    public class Zombi : Character
    {
        public Zombi(Vector2 Position)
            : base(Position)
        {
            this.graphics.texture = EntityTexture.Monster;

            CharactersData data = LoadCharacterData("zombi");

            this.graphics.tile = new Point(data.tilex,data.tiley);
            this.Name = data.name;
            baseAttack = data.baseattack;
            baseDefence = data.basedefence;
        }

        public override void Update(GameTime gameTime, MapEngine.TileMap map, ref Player player)
        {
            // Añadir la IA a partir de aqui.
            if (playerdistance <= 1)
            {
                Character playerchara = player;
                AttackEnemy(ref playerchara);
            }
            else if (playerdistance < 6)
            {
                Random rand = new Random();

                if (rand.Next(5) < 3)
                {

                    float Xdst = position.X - player.getPosition().X;
                    float Ydst = position.Y - player.getPosition().Y;

                    if (Xdst < 0)
                        Move(map, EntityDirection.Right);
                    else if (Xdst > 0)
                        Move(map, EntityDirection.Left);
                    else if (Ydst < 0)
                        Move(map, EntityDirection.Down);
                    else if (Ydst > 0)
                        Move(map, EntityDirection.Up);
                }
            }
            
            base.Update(gameTime, map, ref player);

            
            

        }

        #region -- Serialización/Deserialización --
        public Zombi(SerializationInfo info, StreamingContext ctxt)
            : base(info, ctxt)
        {
        }

        public override void GetObjectData(SerializationInfo info, StreamingContext ctxt)
        {
            base.GetObjectData(info, ctxt);
        }
        #endregion
    }

}
